﻿using System;
using System.Collections.Generic;
using System.Text;

namespace BLL
{
    public static class SpeciallySql
    {
        private static Data.SpeciallySql Data_SpeciallySql = new Data.SpeciallySql();
        public static int run_SpeciallySql(string SQL)
        {
          return   Data_SpeciallySql.run_SpeciallySql(SQL);
        }
        public static System.Data.DataTable getDT_SpeciallySql(string SQL)
        {
            return Data_SpeciallySql.getDT_SpeciallySql(SQL);
        }
        public static long getWebrunbegin_long()
        {
            DateTime datebegin = Data.DBConfig.Begindate;
            if (datebegin == null)
            {
                return long.Parse(DateTime.Now.ToString("yyyyMMdd"));
            }
            else
            {
                return long.Parse(datebegin.ToString("yyyyMMdd"));
            }
        }
        public static string getWebrundate()
        {
            StringBuilder showsb = new StringBuilder();
            DateTime datebegin = Data.DBConfig.Begindate;
            DateTime datenow=DateTime.Now;
            if (datebegin == null || datenow == null)
            {
                showsb.Append("网站已运行：1天");
                return showsb.ToString();
            }
            else
            {
                if (datebegin > datenow)
                {
                    datebegin = datenow;
                    showsb.Append("网站已运行：1天");
                    return showsb.ToString();
                }
                TimeSpan span = datenow - datebegin;
                double tdays=  span.TotalDays+1;
                int intdays =Convert.ToInt32(Math.Floor(tdays));
                showsb.Append("网站已运行：");
                int add = 0;
                if (tdays > 365)
                {
                    showsb.Append((intdays/365) + "年");
                    add = 1;
                }
                if (datenow.Day - datebegin.Day > -2)
                {
                    if (datenow.Month - datebegin.Month > 0)
                    {
                        showsb.Append((datenow.Month - datebegin.Month) + "个月");
                        add = 2;
                    }
                    else if (datenow.Month - datebegin.Month < 0)
                    {
                        showsb.Append((12 - Math.Abs(datenow.Month - datebegin.Month)) + "个月");
                        add = 2;
                    }                   
                    if (add == 1)
                    {
                        showsb.Append("零");
                    }
                    if (datenow.Day - datebegin.Day > -1)
                    {
                        showsb.Append((datenow.Day - datebegin.Day + 1) + "天");
                        add = 3;
                    }
                }
                else
                {
                    if (datenow.Month - datebegin.Month > 1)
                    {
                        showsb.Append((datenow.Month - datebegin.Month - 1) + "个月");
                        add = 2;
                    }
                    else if (datenow.Month - datebegin.Month == 1)
                    {

                    }
                    else if (datenow.Month - datebegin.Month == 0)
                    {

                    }
                    else if (datenow.Month - datebegin.Month < 0)
                    {
                        showsb.Append((12-Math.Abs(datenow.Month - datebegin.Month)) + "个月");
                        add = 2;
                    }
                    DateTime dateJB = datenow ;
                    int them = datenow.AddMonths(-1).Month;
                    bool iserr = false;
                    try
                    {
                        try
                        {
                            dateJB = new DateTime(datenow.Year, them, datebegin.Day);
                        }
                        catch
                        {
                            iserr = true;
                        }
                        if (iserr)
                        {
                            if (them == 2)
                            {
                                dateJB = new DateTime(datenow.Year, them, 28);
                            }
                            else if (them == 1 || them == 3 || them == 5 || them == 7 || them == 8 || them == 10 || them == 12)
                            {
                                dateJB = new DateTime(datenow.Year, them, 31);
                            }
                            else
                            {
                                dateJB = new DateTime(datenow.Year, them, 30);
                            }
                        }
                    }
                    catch { }
                    showsb.Append((datenow.AddDays(1) - dateJB).Days + "天");
                    add = 3;
                }
                if (add == 0)
                {
                    showsb.Append("1天");
                }
            }
            return showsb.ToString();
        }
    }
}
